package hot100.logos1To10;

/**
 * @author logos
 * date 2025/7/9 11:57
 * @version v1.0
 * @Package hot100
 */
public class logos5 {

    /**
     * 5.盛最多水的容器
     * https://leetcode.cn/problems/container-with-most-water/?envType=study-plan-v2&envId=top-100-liked
     */
    class Solution {
        public int maxArea(int[] height) {
            int left = 0;
            int right = height.length - 1;
            int ans = 0;
            int h = 0;
            while (left < right) {
                h = Math.min(height[left], height[right]);
                ans = Math.max(ans, h * (right - left));
                while (left < right && height[left] <= h) {
                    left++;
                }
                while (left < right && height[right] <= h) {
                    right--;
                }
            }
            return ans;
        }
    }
}
